<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>

<body>
    <div id="app">
        <p>{{msg}}</p>
        <!-- 默认是给my-input 动态绑定value值  并添加一个input事件 -->
        <!-- <my-input :value="msg" v-on:input="msg=$event"></my-input> -->
        <my-input v-model="msg"></my-input>
    </div>
    

    <script>
        Vue.component("my-input",{
            props:["value"],
            template:`
            <div>
                <p>我是组件</p>
                <input type="text" :value="value" v-on:input="$emit('input',$event.target.value)">
            </div>
            `
        });
        var app =new Vue({
            el:"#app",
            data:{
                msg:"初始值",
            }
        })
    </script>
</body>

</html>